package com.gym.controller.action.admin;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.gym.model.dao.ConnessioneException;
import com.gym.model.dao.DAOPayment;
import com.gym.model.dao.DatoNonTrovatoException;
import com.gym.model.dao.MetodoDaoException;
import com.gym.model.entity.Payment;

public class FindPayment extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		try {
			DAOPayment daoPayment = new DAOPayment();

			List<Payment> payments;
			try {
				payments = daoPayment.select();
			} catch (MetodoDaoException | DatoNonTrovatoException e) {
				payments = new ArrayList<Payment>();
			}
			request.getSession().setAttribute("comboPayment", payments);

			return mapping.findForward("success");

		} catch (ConnessioneException e) {
			request.setAttribute("error", e.getMessage());
			return mapping.findForward("failure");
		}
	}
}